Re-organise and add documentation.