refactored lib into models