Fixed bugs and added sample test cases. DONE.