Smarter way of handling across loop functions