image module refactored (ready for going upstream)