Refactored the main client program