code rearranged for adding routing
phrases sort by time also