Rubyfied the code after review by dmacvicar