working version with both types of data