Pull in some bugfixes by sm6xmm and Omwah