refactored code and reflection