Updated semaphore code - now waiting until value is zero