fixed image buffering algorithm (again!)