changes identified during code review - fixed access check and made some code more readable