add logic in the already existing "delete" function