added preliminary support for double buffering