Courtesy to @Rabenda I took the liberty of polishing and tidying up the comments, otherwise it should work as intended.