implemented double buffering