Replaced malloc with new[]