Fix loops. Now nested loops should work properly