Fixed Syntax errors and bugs! And add test cases.