refactor the lib