Adds comments to code, adds minor sanity chekcs etc