clean up code, support flatten
add some simple tests
update readme for publishing