refactored lib