More refactoring and add count method