fixing flag problem