Fix some more defects.
Fix Peter's comments.
Merge pull request #569 from nomis52/master

Fix some more defects.