Added support for predicate functions.
Make sure the states object is normalized before we try to use it.