prevented flicker, optimizing code