rearrange main into sections by topic
add missing include guards
split value streams from main program