refactor validator, fix tests