Need help in debugging an IF condition