Reorder if, add local variable

No functional changes