Minor code improvements for lib.js. closes #580