-\State $s_p \gets MaxLastSeqN(MS)$\r
-\State $max'_p \gets \Call{CheckResize}{MS,th_p,max'_g,m'_p}$\r
-\State $need_p \gets \Call{CheckNeedSS}{MS,max'_g}$\r
-\State $DE_p \gets \Call{GetDEPairs}{KV,max'_p,need_p,sl_{last}}$\r
-\State $hmac_{c_p} \gets Hmac(DE_p,SK)$\r
-\State $Dat_p \gets CreateDat(s_p,id_{self},hmac_{p_p},DE_p,hmac_{c_p})$\r
-\State $hmac_{p_p} \gets hmac_{c_p}$\r
-\State $sv_p \gets Encrypt(Dat_p,SK)$\r
-\State $\tuple{stat_p,SL_p} \gets \Call{PutSlot}{s_p,sv_p,max'_p}$\r
-\State $cr_p \gets \Call{HandleCollision}{\tuple{stat_p,SL_p}}$\r
-\If{$need_p$}\r
- \State $cr_{p_{last}} \gets \Call{ReinsertLastSlot}{sl_{last},max'_p}$\r
-\EndIf\r
+\State $success \gets false$\r
+\While{$\neg success$}\r
+ \State $s_p \gets MaxLastSeqN(MS)$\r
+ \State $max'_p \gets \Call{CheckResize}{MS,th_p,max'_g,m'_p}$\r
+ \State $need_p \gets \Call{CheckNeedSS}{MS,max'_g}$\r
+ \State $DE_p \gets \Call{GetDEPairs}{KV,max'_p,need_p,sl_{last}}$\r
+ \State $hmac_{c_p} \gets Hmac(DE_p,SK)$\r
+ \State $Dat_p \gets CreateDat(s_p,id_{self},hmac_{p_p},DE_p,hmac_{c_p})$\r
+ \State $hmac_{p_p} \gets hmac_{c_p}$\r
+ \State $sv_p \gets Encrypt(Dat_p,SK)$\r
+ \State $\tuple{stat_p,SL_p} \gets \Call{PutSlot}{s_p,sv_p,max'_p}$\r
+ \State $success \gets stat_p$\r
+ \If{$\neg success$}\r
+ \State $cr_p \gets \Call{HandleCollision}{\tuple{stat_p,SL_p}}$\r
+ \EndIf\r
+ %\If{$need_p$}\r
+ % \State $\tuple{cr_{p_{last}},hmac_{p_p}} \gets \r
+ % \Call{ReinsertLastSlot}{MS,SK,sl_{last},max'_p,hmac_{p_p}}$\r
+ %\EndIf\r
+\EndWhile\r
+\State $MS \gets \Call{UpdateLastSeqN}{id_{self},s_p,MS}$\r