Change some code to use coroutine