Fix counting of inserts and undefined variable

Signed-off-by: emanuele <emanuele45@gmail.com>