some diagnostics code & bugfixing