major refactoring, half done.
More refactoring, pretty nice now :p