Remove empty prefixes and suffixes