Added additional check for empty array