Fix bugs in setting session