Code cleanup

Had time before deadline to clean up repeated function calls