halves function extracted.