Updated to replace function