Improved type conversion and added tests.