Refactor type classes definition