refactoring to take advantage of Predicates and Function composition