Well, don't feel too bad, cause I'm not even sure that will work under all conditions.

I should do some testing.