Check optional elements if they have a value.

Leaving optional fields blank is (presumably) a valid option, so this
update ensures that optional elements are only validated if a value was
actually specified.
Refactoring for increased usability.