Code cleanup, add some hopefully useful comments