refactor the code to avoid creating temp arrays when geting a line