organise code and add documentation