Fixed flickering.

Fixed flickering by applying a fix I got from StackOverflow.