fixed a lot of tests and build system so taht 'make qtest' works.
Still a few things to fix.