improved code for main method