cleanup jpeg writing and various other cruft