Applying original patch after conflict fix

I've fixed conflicts in the previous PR.