Thanks.

I was worried about the complexity behind this, too, but didn't find another way to solve it as well. Maybe @rfk or @tarekziade?

+1 Will definitively put the code into a different function.