Imported fix from Christian (it's all his fault if this goes wrong)