Another major refactoring of all the library