Refactor script

Make script more robust and easier to read. Functionality and usage remain
unchanged.
Merge pull request #1 from apeschel/master

Refactor recolor script.
Merge pull request #1 from twain47/master

pull ustream