Composing closures to avoid looping more than once