[FIX/ENHANCE] Session management

[FIX/ENHANCE]  Session management
@herrkauwer appreciate the code review and help
@xisi initial code pr
@add1ct3dd reporting the issue


Further enhances #1558