finish main function