added some safeguards to prevent error spam