simplifies inserts, move last element checking outside for()