Attempting to sanitize the input. I beleive that there are a few cases where invalid input get through.
moved the error message generating code into the color sanitizing method
Moved the most likely case to be first