Dm upgrades

 - major re-factoring to reduce duplicate code
 - added PIMS object to iterate over images.