added an upper/lower function and simplified the count function