Refactored validation and tests for it