Refactored with functions.