Move to buffered reads to improve performance
Make all unref function handle NULLs gracefully
Add missing #ifdef PTHREAD
Added asynchronous reader to improve input read speed
Add thread-friendly output writing system
Update indentation