minor reordering to hopefully slightly boost speed