Small fixes and improvements from static analysis