Deduplicate some code about borders