Moved the test counter into the returned function so the counter resets each time it's invoked