Cherry-pick from 63371c24ab470e2ab4f7dd86e78e4c8080b5fd6e (attempt to fix #27)