Ok, this code works, needs cleanup and session destruction added to it