more optimization, especially for jpeg