Merged and modified the latest version of the model code from
TrainPuzzle, as was submitted for the final iteration.