helper function extracted.