Refactor to pull opening the file out of the count function
Clean up indentation and whitespace