Pull in most recent upstream code

There are a few conflicts in here but it will mean less of a headache in the future.