Refactor validity checking for type/data instances