use local int and boolean to keep track of changes.