Small refactor plus more validation.