building array of arrays in controller to make accurate pagination possible