Separated the common codes into analysis.cpp.