Added some type casts to allow building with GCC 4.6.3