fixed the memory corruption problem by declaring buf[] on the stack in
local scope as opposed to the heap
worked on terminate and cleaned up some prints