Cleanup and input validation for type encoder classes