tests for replace rule & bug fixes for replacement