Refactored semaphores to use dispatch_sync