Modified main.cpp to be more general and clearer