removed extra allocation from inner loop