Cleaning up some code

Made some errors consistent with the java version and cleaned upsome code.