Fixing flag functionality