use function to bind promises to loop scope