refactored by creating an image object