Finish main function