Made closeWithCode:reason: safer by moving readyState change into the work queue