error detecting routine