remove nested loop