Inverted some conditions to decrease the identation and improve readability.