Implemented interim image output. Fixed a bug about thread-safety.