Changed some variables, refactored some code