Add lib.coffee, optimize lib.js. Closes #326.