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.