Fix array ref error, and some more debugging