First good working version!

Tested with a demo app (to be added in future)