Move replace func to top