Extract data pid logic to own function