Backported two fixes