Refactoring the whole lib