fix bug with data being overwritten