Modified solution with counter