Improved parenthesis matching

I ommitted regenerating tests so that you can check the output. Only 13 failures, most of which look like improvements though!