Lots of neat little tricks in this code to get it so concise. Pretty understandable too, after a bit of thought.