better segmentation into smaller functions