Initial code and examples

This is not tested enough. Need more tests.