Added static_casts to make C+11 compliant