put __main__ code into main(), take generate config function into two
function
modify code architecture and mrthods