Added cleanup of semaphore