reorganized/cleaned code design

(untested)
further code cleaning