Refactor of reading contents of file