Updated example with working counter