Small fix in session.inc and extension of reference incrementation algorithm