Refactored code, removed unused code