Ensure function exits properly