Update to use UtilLib

Also reformat and document the code