Some code cleanup, including removal of some unused code.
More code clean up. Also added some comments.