nested loop bug. cleaning