Currently the code is very repetitive concerning validation of session tokens. This needs to be cleaned up and put into a separate function.