Made validation code more concise