Refactor lib directory