Refactors code
Still needs refactoring..