refactoring the code to make it more readable

Refactored the main.cpp to be less "dirty".