Refactored version.