))

Apart from some very minor style differences, this code almost looks like I wrote it o_O