Move that check, now it should work correctly.