fully functional border function