Added When Exit Function (Safe Exit)