slightly more efficient replace