cleaned up for loop implementation