Fix synchronization issue in delete function