Rename variable "flag" to "state"