Cleaned the warning of undefined index by checking if the index is set