Back port the changes from f4f678264021ed86e9bba57854cc9346ce6a3f62