Initial code

Basic functionality verified. Some unit tests written.