code cleanup and smooth color legend display bug fixes