          input,
          output,
          z_index,
-         %{x_index: x_index, y_index: y_index, x_pos: x_pos, y_pos: y_pos, tile_size: tile_size}) do
+         %{x_index: x_index, y_index: y_index, x_pos: x_pos, y_pos: y_pos}) do
 
     {
-    "mkdir -p /imageroot/wes/#{output}/#{z_index}/#{x_index}/#{y_index}",
-    "convert"
-    <> " /imageroot/wes/#{input}"
-    <> " -crop #{tile_size}x#{tile_size}+#{x_pos}+#{y_pos}"
-    <> " -background transparent"
-    <> " -extent #{output_tile_size}x#{output_tile_size}"
-    <> " /imageroot/wes/#{output}/#{z_index}/#{x_index}/#{y_index}.png"}
+      "mkdir",
+      [
+        "-p", "/imageroot/wes/#{output}/#{z_index}/#{x_index}"
+      ],
+      "convert",
+      [
+        "/imageroot/wes/#{input}",
+        "-crop", "256x256+#{x_pos}+#{y_pos}",
+        "-background", "transparent",
+        "-extent", "#{output_tile_size}x#{output_tile_size}",
+        "/imageroot/wes/#{output}/#{z_index}/#{x_index}/#{y_index}.png"
+      ]
+    }
   end
 
   defp create_template(size, output_tile_size) do

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

    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)
