Probably should have committed sooner than this, but anyway. Here's the starting point, including tests