refactoring palette code
consolidating
major refactoring to better compartmentalize the code