added double buffering code, maybe.