Moved the reflection function logic to its own function