Factored out the reading data step to speed up code