Refactor: Replace malloc with std::vector