more tests, better docs and generate function