Refactor using reflections class method.

Via @vuvanly in #357.