Fixed bug in delete function