image processor code refactoring