ticket 4686: Refactored code. Code now conforms top PEP8
Refactored formatting code into the helper. Also, ran pep8 on
palettes.py. Code now conforms to PEP8.