Fix #511

Thanks to @aforemny for discovering and reporting the issue!