added code for handling exception more gracefully, and improve code for aligning logout to the right