Refactor the validate implementation a bit