Improved the calculation of the border color