corrected data storage function