grouping and extracting script for sample code