logout function refine