refactor first three problems