fixed notices and cleaned up code when saving images