switched to sparse arrays for performance