Added array check to avoid exceptions