faster version for zigzag convert.