Loops optimization