Fix delete function bug