Fix some bugs, add fixtures for tests.