added double buffering