optimize hbox algorithm