use correct prefix reduction instead of pattern replacement