switched to semaphores to put limit on the number of threads