better close paren/bracket handling