Added occurrence count method with while loop