Add test framework, and found som bugs fixed with it.