Added test cases with mocha/chai, did more error checking