Improving the border drawing function