Factored out redundant if ($handler) checks.