reorder branches in function