refactoring codes; adding object deletion event