Removed excessive operations out of iteration loop