initial working and documented version

- needs tests