Added reading of model name, some refactoring