slight optimisation not calling Length(X) in for loop