fix to replace function