Fixed incorrect order of releasing resources
Grauded an error of deleting databag when undeploy