A bunch of refactoring around validation