Added input string parsing and a bunch of functions in to handle the model.