Change if() login to handle array index not being present