Loop logic updated