Some heavy refactoring

With love of course, still not very pretty