fix busy waiting and getting stuck