Fixed a bug in calculating a color