type conversion improvements

Several improvements in type conversion and related junit tests