code optimization in create Flag API