refactored image handeling