Code review issues - added comments and refactored.