Use (use-region-p) instead of mark-active, as pointed out by the elisp manual