Changed order of predicates and fixed IF case