Added support for double/triple buffering