change to pass the range of counter
remove unused variables