refactored to remove temp variable