Fix memory leaks & Use correct "delete" for arrays