finished main function