added counter function