also fixed Insert and Replace functions