add implementation of binary_replace