moved functions/added comments/minor fixes
minor fix