Major refactoring

Pre 1.4.0