Completed sign in/out function