Fix memory errors due to large image and history buffer