better border calculation