changed recursiveRemove function