Fix replace function and a failing test for subresource lookup.
add test for replace()