Fix replace function and a failing test for subresource lookup.