abstract the closure out into function