fixing recursive method for finding replacements