Added assertion safety checking to the parser and fixed testcases