gc function and safer session management