Refactored code

Code is now more readable and has more comments