pull out login session check into function
pull out redirect code into function