Cleaned up some comments, added some comments; logic unchanged.