lib refactored