Implements the coroutine framework