improving algorithm for flagging global context features