some code cleanup,
 putting functions in order of dependency, go through the whole code and annotate concerns.