Refactored ImagePart and logic into classes/functions