Tidying up and adding documentation