Some changes in main function algorithm