Extract more functions into util.