add and fix a couple comments for dup image prevention code
fix up dup image name prevention code, plus reorder some things to make it more reasonable