Improve session close callback API and utility functions.