Model validation

Add support for model validation. All tests passing, all examples tested.