use boolean flag correctly