Attempt to fix data loss during session end
Merge pull request #434 from Gelmir/session_end

Attempt to fix data loss during session end v2