Moved some common site operations to functions. Log in/out improvements.