refactoring palette code.