added predicates and fixed code