Refactored type conversion into a separate namespace, added unit tests for it.