Improved the logic used when applying weak BCs.