Patch by Ivan Krstic, slightly modified, for the session handler wrong setting problem.