if function fix

Change optimization to use len function as test condition