refactoring and incorporate robert's dpi conversion routine