corrected if array bug