Add documentation, and do some cleanup