Again, heavy refactoring