fixed errors, given by cppcheck and valgrind