Mess of functionality and refactoring