handling async tasks correctly