these code segment to handle five colors are identical expect color parameter, could you extract them to a function and avoid redundancy?