Merge code from loadFromFile and loadFromString into one private method