implemented logout code and minor tweaks