solved bug with replacement pairs and distance=2

This solves a bug when using replacement pairs with max distance=2. Previously the distance was not calculated when the replacement took place at the end of a word.