Adding documentation and minor tidy ups