Refactor and implement initFromFile