refactored the loop for rendering of arrays