Added explicit casts to make C++11 compiling work