improves the bak and inplace replacement