error logging for individual sections and some refactoring (test-lib.js)