relocate writeCounter defn to the proper place (where it's are used)