Array length caching seemed to be breaking the application