Move validators to own file, add tests

Other cosmetic changes.