Many minor bug fixes. Made functions work. Added Mocha tests