altered code to account for borders