Rewrite delete function so that supports better chain removing