Added atomic operation to increment the counter