Add validation functions and tests