Code Tidy-up and Documentation