Corrected many small bugs in arim_lm_agg

It would be better to use circularly stored arrays.