Improved main.cpp response generation structure