Refactored color fading algorithm, now more portable by using callback function