moved counter out into separate js for readability