logout function enahnced