added proper comments to utils, tidied up code