removed memory leaks, added some further tifflib debug code and added a
validation function.