Fix border calculation