Refactored background animation code.