fixed #1723
moved logic to Session object and added test case
Merge pull request #1724 from daftshady/dev3

Fixed #1723