Fix defects from static analysis