added new functional session key
cleaned up code