Added self-test files. Fixed bugs.