use delete where appropriate to get rid of mallocs. Fix issue where kbstate data1 and data2 were not null terminated