move validation code to proto