refactor and implement undeploy and redeploy