Updated onBeforeDelete logic and unit tests