Improved fix for #607