revert foreach into for