Thanks. I stole this from line 70ff...