refactored jpg and png optimiser