Fix boundary calculations.