This cleanup step and the same one in handle_data strike me as belonging in finally blocks.