added more error handling debug statements