working version of the data extraction