Change interface for flatten(), update tests, move some stuff around and add comments.
Start writing readme.