Diagnostics - improted most of the code, it now builds, preparing for refactoring and review