cleaned up util functions and added comments - trinker please read.