implemented checkFlag function