added counter and some logging