Rewritten logic to use dynamically allocated network arrays