Refactored library code