initial porting of code

- extracted from existing project
- still needs traits support