Added test cases and fixed a few errors