improvement over previous implementation, no need to hold a stack of parens