Formatted code, refactored some variables