some modifications in Main function