Tidied up some code, refreshed doc.