Fix more problems found by Steve Grubb, along with other changes: