Replaced while condition + updates

KMS-3488 #time 3h