Refactorring to lib