Code review, misc changes

Hi.  I just did a little code review and fixed a few thing and tidied a few others.  Please review.