parentheses are now correct in output, though last term in if has redundant pair.