changed the data parsing to a function