Refactor C++ query server