Reworked logout function.