fixed some minor bugs as suggested by clang analyzer