Fix potential bug

Added `default` to prevent notices and reordered the code.