Refactored deployment steps into separate phases, added undeploy operations in correct order.