Fix a few issues identified via static analysis