Refactoring library code for tests