replaced malloc with new && fixed a bug