Cleaning up and using peek instead of backtracking