* extract common logic