Use a Set instead of a list of used vars
Move List.rev closer to the creation point
More precise error location for pattern matching