moved replace to closed function