Refactored type conversion code into classes