Replaced malloc with new

replaced all mallocs with new and all frees with deletes