Refactored code and cleaned up code