Correct error message
Delete dead code
Refactor: Replace malloc buf with std::vector