Modified calculation of boundary conditions for better consistency.