added zigzag conversion