modified delete function
(still doesn't work well)