working version
TODO
clean tests