Create counter function