trying a refactor
refactored out the extra variables into functions
changed the shbang to work on mac