initialize flag and counter

Initialize flag and counter for avoiding to use uninitialized variables