Add documentation, tidy up