Cleaning up the code to reduce duplicated type conversions.