removed duplicate looping code