refactor reflection code