Merging Tim's changes into the current master

He has a lot of good fixes.