Fix leaking dynamic store session object + minor optimizations