The original was causing the bug Mailaender was describing above. The new if does work correctly.