Added more casts to replace static_cast