rewrite longest valid parentheses and add some comments