Fixing memory leaks.
Bugfix regarding applications that open multiple sessions.