Updated the validate function