Move the update of lastLogicalTop out of the for loop