better segmenting into smaller subfunctions