add some checking and logging, mostly related with mantis issue 3671