complete main function