improved count method