better locking to prevent flicker