code cleanup, fixed pthread stuff, buffer closer to being normal, but not quite.