Fix taken from master branch