Refactored Longest Valid Parentheses