Added some explicit casts to avoid warnings in some cases