fix bugs found by static analyzer