Add a huge load of doc strings, a license and do some code cleanups