       if run != :ok do
         nil
       else
-        template = List.flatten(calc_template(current_size, output_tile_size, scale_factor))
+        tmp = calc_template(current_size, output_tile_size, scale_factor)
+        template = {current_size, List.flatten(tmp)}
         if current_size < output_tile_size do
           {template, {:halt, current_size, scale_factor*2}}
         else

                %{
                  x_index: x_val,
                  y_index: y_val,
                  tile_size: scale_factor * tile_size,
                  x_pos: x_val * tile_size * scale_factor,
                  y_pos: y_val * tile_size * scale_factor
                }
              ]
            end

    size = 6000
    tile_size = 256

    template = create_template(size, tile_size)

    commands = Enum.map(template, fn {{rescale, entries}, z} ->

      rescale = floor(rescale)
      IO.puts "rescale to #{rescale}"
      System.cmd("convert",
             [
               "/imageroot/wes/6c5f936b-dba9-bf57-b681-5fc292e00e0b.jpg",
               "-resize",
               "#{rescale}x#{rescale}",
               "/imageroot/wes/6c5f936b-dba9-bf57-b681-5fc292e00e0b.#{rescale}.jpg"
             ]
      )
      Enum.map(entries,

        fn entry ->

           {cmd_a, args_a, cmd_b, args_b} = make_commands(tile_size, "6c5f936b-dba9-bf57-b681-5fc292e00e0b.#{rescale}.jpg","6c5f936b-dba9-bf57-b681-5fc292e00e0b",z, entry)
           System.cmd(cmd_a, args_a)
           IO.puts "#{cmd_b} #{inspect args_b}"
           System.cmd(cmd_b, args_b)

           entry

        end)
    end)
