Fix bugs related to session