Refactored with functions