Fixed C++11 compiler warnings/errors (mostly by adding ugly casts).