fixed counting of existing values