Added some documentation and tidy up