centralize validation logic