Add extract_subset function