added double buffering to prevent tearning