refactored with extract method