Fix some bugs reported in the test