refactor and compress images