improved session cleanup and memory use