I've made the code as small as possible, but since the occurrence of the error very much depends on the context, some context code is necessary.