better validate function