Added a semaphore to prevent useless repaints