found Bram's code for much cleaner implementation