[FIX/ENHANCE] Session management

@herrkauwer appreciate the code review and help
@xisi initial code pr
@add1ct3dd reporting the issue
Merge pull request #1559 from Neozonz/issue-1558

[FIX/ENHANCE] Session management