Fixed mad refactoring. Also removed some unnecessary code.