Initial revision.

Moved over from sandbox and dusted off a bit.
Using a more readable implementation.

Also added a test or two.