Port fix for #425 from commit d9c798b4e