Merged changes with jpeg saving