Moved function into container loop