Fix many static analysis warnings