Minor API adjustments. Implemented replace(...) {...} macro with tests.