Implemented the use of pthread_join

Will probably go back to the signal variable because it separates sections of code nicely. For now this works
Changed stream state signal to bitflag. Added debug definitions