Fixed some bugs in the coloring routine