logout function and fixes