Implement interleave function.