Use heartbeat to detect closed request.
Refactor view helper.