Abstracted utility methods into a module
Added comments at various places and renamed the variables