Improved assigning of colors to elements