fix count function