Various fixes/clean-up for thread/pipe implementation and tests