rewrite lib.js in plain JS (detach from CS source)