reorder some logic