fixed a bug about closing session