Initial working commit of new implementation.

Needs additional unit tests and performance tests.