Fixes for various invalid type conversions

Minor fixes for warnings related to bad casts.