Refactored code so that calculation for reflected ray is its own function