revised session function