Refactoring, solved some spaghetti