more directly set the icon color, avoiding a crash when walking up the context tree
Some minor refactoring and code improvements