Fix cppcheck and compiler warnings