Fix bugs in parser. Add more unit tests.