added double-buffer mode to reduce flicker