Improved type casting/conversion logic.
* cleanup up recursive hash generation logic (split into several shorter methods)
* moved type casting logic into separate classes