Moved code to Counter and Preferences to be more object-oriented.