Initial implementation.
Rewrite. Started work on tests.