Fixed bug where was saving one extra invalid image