refactored score_segments to functional approach