rework code for simplified segment processing to be more transparent