changed malloc/free to new/delete