[refactor] into C++ tool for better unit testing