Refactoring into lib