replace to use local var instead of accessing array.