Better count function