fixing ftruncate errors, debug stuff included
removed debugging messages