Split the code into different files. Updated main().