Minor fix to insertNewlines function