Code tidy, removing a few unused bits and adding some commenting