(imported from commit 3e8efbfe8bbd5a2f13a8e02d9f44442b035113ba)
Fixes #385. (imported from commit 7dac013debd6ccff031fc4da0dd7185e198b4498)