added check to double array in case of possible out of bounds