Fix potential problem similar to #1545
Add fix for #2054