Fix session wait loop