Ported ModelState.js, see #138