Fixed logout function, closes #164