refactoring + tests for the libray