Tested and fixed color palatte algorithm