Also correctly move resetting the task to the end instead of defer. We don't want to reset the task in the case of an error, so shouldn't use defer.