Fix for nested loops