Edit: removing the function definition eliminates the problem, so I'd say that your diagnosis of the problem is spot on.