Apply some more fixes from PowerWyrm from #1661.