Seperate data reading into a function