* saving working code * add checks for deletion (cherry picked from commit 487dd113b05aa54a8683f6be980a60f3e431d226)