Fix a few issues detected by unit tests