distributed code in main.cpp to smaller files by class functions
to make the code more readable.