This version for Apex.
Refactoring.