Extensive refactoring of everthing.