Added lots of explicit type casts to fix compiler warnings.