fix busy-wait loop