Fix potential bug

Added `default` to prevent notices and reordered the code.
Merge pull request #6548 from SiR-DanieL/patch-2

Fix potential bug