move array cycling to function