move inner function nearer to usage
replace dict comprehension with simpler dict constructor