Fixed bugs found by static analysis.