added scope checking, but haven't tested it works yet
merged changes in parser from Prashant