move alignment out of for loop; check range end