Added plan flag logic