Refactor to use pthreads & proper state machine.  Clean up style, fix alloc
bugs, and also use strtok() from libc.
Merge pull request #11 from gdamore/garrett

Refactor to use pthreads & proper state machine.  Clean up style, fix al...