Updated conversion code to limit null reference errors