updated code to handle different data format