fix for jpeg regression
various bug fixes