large refactoring and integration of library