get rid of redundant prefixes and suffixes