fixed some stuff with semaphore