Fix some bugs reported by John Burnham.