main function and extract