refactor lib.js