Added precedence logic for removal of extraneous parentheses.