Add exitFlag. Fix logging
Dont exit early, wait for the output thread to finish and dont block indefinitely
Merge pull request #22 from mibrahim/master

Add exitFlag. Don't exit early, and don't block forever