remove variable not used and add test for astype.
remove var not used or use them instead of recomputing.
Remove not used var tval, simplify the test and test for the error!