extracted validation logic to module