Fix some bugs in parser and add test