add tests and fixed replacing