refactor of util.js, adding docs. preparing for resizing of images