Re-applied 064ed0ad12007fdf1aa8b8d731b792ecdf41a095 to master