changed counting method for array length