Major refactoring of all the library