Refactoring

Refactored some of code to make it more manageable to the human eye.