Finalized logout function