Modified graceful_close_sessions according to Bart's patch.