lots of refactoring

Trying to make predicates separate from transformers, and passing
transformers to functions. In the meantime, it still works the same.