fixed some couting bugs