change global arrays to dynamically allocated