Fixed the function to convert color to gray