cherrypicking jeroenpraat's pull request