error handling changes to avoid PHP E_NOTICEs