Added error handling for mismatched parentheses