added join to threading b/c output file was not written in sequential order .