Fix data corruption bug