refactor using reflect