This 'whens' is shadowing the 'whens' on line 92.  Pick a different name here to make the code more readable.