Fix: first for nil class.
Refactor: Dry up the code.
Refactor: Use of ternary operator.