Numerous cleanups; switch to threads; binary stdio