write_array.py code refinement