Refactored some code to comply with standards and and reduce complexity.