implement double buffering