Refactor function to be cleaner and not continually redirect people if they are logged in.