Refactored to remove output variable