1) Fix some bugs found by external test suite