fix a few bugs in domain.

Also, add detection on mismathing dtypes of input data.