add better error logging