Refactored code, added comments, added variables