fixed some bugs and added missed test files.