Added core function to close sessions for performance.