Extracted image operations to a new class. And refactored a lot