Fixed bug in sign in/out, and cleaned up code