moved count to global variable