change the code layout, remove reading of the dict,

make some variables global and add some new functons