some fix for optimization (thanks to semaphore)