Made logErrorsFlag global plus some other refactoring and some new prototype modules