Unfinished #112 it mostly works, still needs clean up, rewiev, comments
test, documentation and other things.