Fix a number of issues from master merge.

Not sure if completely done, but hopefully close to working again.